home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / griddemo / gridmain.pas < prev    next >
Pascal/Delphi Source File  |  1996-04-08  |  5KB  |  149 lines

  1. unit Gridmain;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Dblup2, DB, DBTables, DBLookup, Mask, DBCtrls,
  8.   ExtCtrls, Grids, DBGrids, Buttons, DBQCombo, Calendar;
  9.  
  10.  
  11. type
  12.   TForm1 = class(TForm)
  13.     TableGridData: TTable;
  14.     DataSourceGridData: TDataSource;
  15.     TableCust: TTable;
  16.     DataSourceCust: TDataSource;
  17.     DBNavigator1: TDBNavigator;
  18.     DBGrid1: TDBGrid;
  19.     TableGridDataOrderNo: TFloatField;
  20.     TableGridDataCustNo: TFloatField;
  21.     TableGridDataShipVIA: TStringField;
  22.     TableGridDataCheckBox: TBooleanField;
  23.     DBLookupCombo1: TDBLookupCombo;
  24.     DBCheckBox1: TDBCheckBox;
  25.     DBComboBox1: TDBComboBox;
  26.     ImageTrue: TImage;
  27.     ImageFalse: TImage;
  28.     procedure FormCreate(Sender: TObject);
  29.     procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  30.       Field: TField; State: TGridDrawState);
  31.     procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
  32.     procedure DBCheckBox1Click(Sender: TObject);
  33.     procedure DBGrid1ColExit(Sender: TObject);
  34.   private
  35.     { Private declarations }
  36.   public
  37.     { Public declarations }
  38.   end;
  39.  
  40. var
  41.   Form1: TForm1;
  42.  
  43. implementation
  44.  
  45. {$R *.DFM}
  46.  
  47. procedure TForm1.FormCreate(Sender: TObject);
  48. begin
  49.   DBLookupCombo1.Visible := False;
  50.   DBCheckBox1.Visible := False;
  51.   DBComboBox1.Visible := False;
  52.   ImageTrue.Visible := False;
  53.   ImageFalse.Visible := False;
  54.  
  55. end;
  56.  
  57. procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  58.   Field: TField; State: TGridDrawState);
  59. begin
  60. {  If Field.Index = 4 then
  61.     DBGrid1.Canvas.FillRect(Rect); }
  62.   if (gdFocused in State) then
  63.   begin
  64.      if (Field.FieldName = DBLookupCombo1.DataField) then
  65.      begin
  66.        DBLookupCombo1.Left := Rect.Left + DBGrid1.Left;
  67.        DBLookupCombo1.Top := Rect.Top + DBGrid1.top;
  68.        DBLookupCombo1.Width := Rect.Right - Rect.Left;
  69.        DBLookupCombo1.Height := Rect.Bottom - Rect.Top;
  70.        DBLookupCombo1.Visible := True;
  71.      end
  72.      else if (Field.FieldName = DBCheckBox1.DataField) then
  73.      begin
  74.        DBCheckBox1.Left := Rect.Left + DBGrid1.Left + 1;
  75.        DBCheckBox1.Top := Rect.Top + DBGrid1.top + 1;
  76.        DBCheckBox1.Width := Rect.Right - Rect.Left{ - 1};
  77.        DBCheckBox1.Height := Rect.Bottom - Rect.Top{ - 1};
  78.        DBCheckBox1.Visible := True;
  79.      end
  80.      else if (Field.FieldName = DBComboBox1.DataField) then
  81.      begin
  82.        DBComboBox1.Left := Rect.Left + DBGrid1.Left;
  83.        DBComboBox1.Top := Rect.Top + DBGrid1.top;
  84.        DBComboBox1.Width := Rect.Right - Rect.Left;
  85.        DBComboBox1.Height := Rect.Bottom - Rect.Top;
  86.        DBComboBox1.Visible := True;
  87.      end
  88.   end
  89.   else {in this else area draw any stay behind bit maps}
  90.   begin
  91.     if (Field.FieldName = DBCheckBox1.DataField) then
  92.     begin
  93.       if TableGridDataCheckBox.AsBoolean then
  94.         DBGrid1.Canvas.Draw(Rect.Left,Rect.Top, ImageTrue.Picture.Bitmap)
  95.       else
  96.         DBGrid1.Canvas.Draw(Rect.Left,Rect.Top, ImageFalse.Picture.Bitmap)
  97.       {  DBGrid1.Canvas.StretchDraw(Rect, ImageFalse.Picture.Bitmap); }
  98.     end
  99.     { Do bit map dwawing if you want}
  100.    { DBGrid1.Canvas.FillRect(Rect); }
  101.   end;
  102.  
  103. end;
  104.  
  105. procedure TForm1.DBGrid1ColExit(Sender: TObject);
  106. begin
  107.   If DBGrid1.SelectedField.FieldName = DBLookupCombo1.DataField then
  108.     DBLookupCombo1.Visible := false
  109.   else If DBGrid1.SelectedField.FieldName = DBCheckBox1.DataField then
  110.     DBCheckBox1.Visible := false
  111.   else If DBGrid1.SelectedField.FieldName = DBComboBox1.DataField then
  112.     DBComboBox1.Visible := false;
  113. end;
  114.  
  115. procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
  116. begin
  117.   if (key <> chr(9)) then
  118.   begin
  119.     if (DBGrid1.SelectedField.FieldName = DBLookupCombo1.DataField) then
  120.     begin
  121.       DBLookupCombo1.SetFocus;
  122.       SendMessage(DBLookupCombo1.Handle, WM_Char, word(Key), 0);
  123.     end
  124.     else if (DBGrid1.SelectedField.FieldName = DBCheckBox1.DataField) then
  125.     begin
  126.       DBCheckBox1.SetFocus;
  127.       SendMessage(DBCheckBox1.Handle, WM_Char, word(Key), 0);
  128.     end
  129.     else if (DBGrid1.SelectedField.FieldName = DBComboBox1.DataField) then
  130.     begin
  131.       DBComboBox1.SetFocus;
  132.       SendMessage(DBComboBox1.Handle, WM_Char, word(Key), 0);
  133.     end;
  134.   end;
  135. end;
  136.  
  137. procedure TForm1.DBCheckBox1Click(Sender: TObject);
  138. begin
  139.   if SendMessage(DBCheckBox1.Handle, BM_GetCheck, 0, 0) = 0 then
  140.      DBCheckBox1.Caption := '  ' + 'False'
  141.   else
  142.      DBCheckBox1.Caption := '  ' + 'True'
  143. end;
  144.  
  145.  
  146. end.
  147.  
  148. Notes > make sure to set the color of the checkbox to match the backgroung
  149.